package com.hnevc.mallserver3.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnevc.mallserver3.dto.CommentDTO;
import com.hnevc.mallserver3.dto.Page;
import com.hnevc.mallserver3.entity.Comment;
import com.hnevc.mallserver3.mapper.CommentMapper;
import com.hnevc.mallserver3.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    // 实现业务方法
    @Autowired
    CommentMapper commentMapper;
    public CommentDTO selectCommentById(Long id) {
        CommentDTO commentDTO =  commentMapper.selectCommentItemsById(id).get(0);
        return commentDTO;
    }

    @Override
    public List<CommentDTO> selectCommentByGoodsId(Long id) {
        List<CommentDTO> commentDTOs =  commentMapper.selectCommentItemsByGoodsId(id);
        return commentDTOs;
    }

    @Override
    public List<CommentDTO> listByPage(Long id, Page page) {
        Long from = (page.currentPage-1)*page.pageSize;
        Long size = page.pageSize;
        List<CommentDTO> commentDTOs =  commentMapper.selectCommentItemsByGoodsIdByPage(id, from,size);
        return commentDTOs;


    }

}
